package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.SkuInfo;
import com.atguigu.gmall.product.service.SkuInfoService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@ToString
@Slf4j
@RestController
@RequestMapping("/admin/product/")
public class SkuInfoController {

    @Autowired
    SkuInfoService skuInfoService;


    @PostMapping("/saveSkuInfo")
    public Result saveSkuInfo(@RequestBody SkuInfo skuInfo){
        log.info("SKUINFO:{}",skuInfo);

        boolean b = skuInfoService.saveSkuInfo(skuInfo);

        return Result.ok();
    }

    //http://api.gmall.com/admin/product/list/{page}/{limit}
    @GetMapping("/list/{page}/{limit}")
    public Result<Page<SkuInfo>> listSkuInfo(@PathVariable Long page,
                                                   @PathVariable Long limit){
        Page<SkuInfo> skuInfoPage = new Page<>(page,limit);
        Page<SkuInfo> skuInfoPagelist = skuInfoService.page(skuInfoPage);

        return Result.ok(skuInfoPagelist);
    }

    //http://api.gmall.com/admin/product/onSale/{skuId}
    @GetMapping("onSale/{skuId}")
    public Result onSale(@PathVariable Long skuId){
        boolean b = skuInfoService.onSale(skuId);
        return Result.ok();
    }

    //http://api.gmall.com/admin/product/cancelSale/{skuId}
    @GetMapping("cancelSale/{skuId}")
    public Result cancelSale(@PathVariable Long skuId){

        boolean b = skuInfoService.cancelSale(skuId);
        return Result.ok();
    }
}
